package com.zhongwang.mms.module.half.controller;

import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.half.model.HInBillModel;
import com.zhongwang.mms.module.half.service.HBasicService;
import com.zhongwang.mms.module.half.service.InAluminWarService;
import com.zhongwang.mms.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description: 铝料入库
 * @author: th
 * @time: 2020/6/12 9:21
 */
@Controller
@RequestMapping("/half/halWarManage/inAluminWar")
public class InAluminWarController {

    //页面文件路径
    private String prefix = "half/halWarManage/inAluminWar";

    @Autowired
    private HBasicService HBasicService;
    @Autowired
    private InAluminWarService inAluminWarService;

    @GetMapping("/page")
    @RequiresPermissions({"halwar:halpurinwar:view"})
    public String create(Model model) {

        // 获取登入用户实体
        User user = ShiroUtils.getUser();
        model.addAttribute("dept", HBasicService.getDept());
        model.addAttribute("warInfo", HBasicService.getWarInfo());
        model.addAttribute("userName", user.getName());
        model.addAttribute("odrDate", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        return prefix + "/list";
    }

    /**
     * 创建铝料入库单保存
     * @param hInBillModel
     * @return
     */
    @ResponseBody
    @PostMapping("/create")
    @RequiresPermissions({"halwar:halalinwar:edit"})
    public JsonResult create(@RequestBody HInBillModel hInBillModel) {

        return inAluminWarService.saveHInBillModel(hInBillModel);
    }
}
